<template>
  <div >
       <el-form
        autocomplete="off"
        :model="loginForm"
        ref="loginForm"
        label-position="left"
      >
      
        <!-- <h2 class="login-title color-main">mall-admin-web</h2> -->
        <el-form-item prop="uaccount">
          <el-input
            name="uaccount"
            type="text"
            v-model="loginForm.eaccount"
            autocomplete="on"
            placeholder="请输入用户名"
            
          >
            <span slot="prefix">
              <i  class="el-icon-user-solid"></i>
            </span>
          </el-input>
        
        </el-form-item>
        <el-form-item prop="upwd">
          <el-input
            name="upwd"
            :type="pwdType"
          
            v-model="loginForm.epwd"
            autocomplete="on"
            placeholder="请输入密码"
            
          >

            <span slot="prefix">
              <i  class="el-icon-key"></i>
            </span>
            <span slot="suffix" @mousedown="showPwd" @mouseup="hidePwd">
              <i  class="el-icon-view"></i>
            </span>
          </el-input> 
        </el-form-item>
        <el-form-item style="margin-bottom: 60px">
          <el-button
            style="width: 100%"
            type="primary"
            :loading="loading"
            @click.native.prevent="handlELogin"
          >登录</el-button>
        </el-form-item>
      </el-form>
  </div>
</template>
 
<script>
import { mapMutations } from 'vuex';

export default {

  
  data() {
    return {
      loginForm: {
        eaccount: "",
        epwd: "",
      },
      
     
     
      result: ''
     ,


      loading: false,
      pwdType: "password",
    };
  },
  methods: {
  ...mapMutations(['changeLogin']),

    
    handlELogin() {
      
        // this.loading = true;
          let t=this;
    if (this.loginForm.eaccount ===''||this.loginForm.epwd ==='') {
        alert('账号或密码不能为空');
      }else{
          this.$axios.post("http://localhost:8888/hs/ever-login/accountLogin",this.loginForm)
          .then((res) => {      
         console.log(res)
            t.result=res.data.result;
            

          //得到result
          // 将用户result保存到vuex中
          t.changeLogin({ Authorization: t.result ,urls:res.data.urls});
          t.$router.push('/Menu');
            this.loading = false;
                }).catch(error=>{
                  // alert("账号或者密码错误")
                  console.log(error);
                })
                }
    

       




      
      // // .catch(err => {
      // //   console.error(err); 
      // // })
     
      //  }else{alert("账号或者密码不能为空")}
    },


    showPwd() {
        this.pwdType = "";  
    },
    hidePwd(){
      this.pwdType = "password";  
    },
  }
};
</script>
 
<style >

</style>